
# -*- coding: utf-8 -*-

from logging.config import dictConfig

def setup_logging():
    logging_config = {
        "version": 1,
        "disable_existing_loggers": False,
        "formatters": {
            "default": {
                "format": "%(asctime)s - %(name)s - %(levelname)s - %(message)s",
            },
            "detailed": {
                "format": "%(asctime)s - %(name)s - %(levelname)s PID(%(process)d)-TID(%(thread)d) - %(message)s",
            },
        },
        "handlers": {
            "console": {
                "class": "logging.StreamHandler",
                "formatter": "default",
            },
            "file": {
                "class": "logging.FileHandler",
                "formatter": "detailed",
                "filename": "fastapi_app.log",
            },
        },
        "loggers": {
            "": {
                "level": "INFO",
                "handlers": ["console", "file"],
            },
            "fastapi": {
                "level": "DEBUG",
                "handlers": ["console", "file"],
                "propagate": False
            },
            "sqlalchemy": {
                "level": "INFO",
                "handlers": ["console", "file"],
                "propagate": False
            },
            "sqlalchemy.engine": {
                "level": "INFO",
                "handlers": ["console", "file"],
                "propagate": False
            },
            "sqlalchemy.pool": {
                "level": "INFO",
                "handlers": ["console", "file"],
                "propagate": False
            }
        },
    }
    dictConfig(logging_config)